// JavaScript Document

/**
 * import compontent 
 */
Vsg.importClass(
	[
	]
);

Vsg.loadExtLibs([
	"miframe.js"
	]
);

/** ===============================
 * init ui interface 
 * ================================
 */
function init(){

	try {
		
		var $tabsArray = [];

		$tabsArray.push({
			title:"概念",
			items:[{
				id:"if1",
				header: false,
				xtype:"iframepanel",
				height:200,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"concept" , name:"concept",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-concept']
			}],
			layout:"fit",
			id:"tab1"
		});

		$tabsArray.push({
			title:"板 块",
			items:[{
				id:"if2",
				xtype:"iframepanel",
				height:200,
				header: false,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"plate" , name:"plate",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-plate']
			}],
			layout:"fit",
			id:"tab2"
		});

		$tabsArray.push({
			title:"行 业",
			items:[{
				id:"if3",
				xtype:"iframepanel",
				header: false,
				height:200,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"trades" , name:"trades",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-trades']
			}],
			layout:"fit",
			id:"tab3"
		});

		$tabsArray.push({
			title:"证监会行业",
			items:[{
				id:"if4",
				xtype:"iframepanel",
				header: false,
				height:200,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"standardTrades" , name:"standardTrades",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-standardTrades']
			}],
			layout:"fit",
			id:"tab4"
		});

		$tabsArray.push({
			title:"同一主力/机构",
			items:[{
				id:"if5",
				xtype:"iframepanel",
				height:200,
				header: false,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"sameStockHolder" , name:"sameStockHolder",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-sameStockHolder']
			}],
			layout:"fit",
			id:"tab5"
		});

		$tabsArray.push({
			title:"区 域",
			items:[{
				id:"if6",
				xtype:"iframepanel",
				height:200,
				header: false,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"zone" , name:"zone",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-zone']
			}],
			layout:"fit",
			id:"tab6"
		});

		$tabsArray.push({
			title:"其 他",
			items:[{
				id:"if7",
				xtype:"iframepanel",
				height:200,
				header: false,
				border:false,
				loadMask:true,
				frameConfig:{autoCreate:{id:"others" , name:"others",frameborder:0}},
				defaultSrc:UrlMKey['stk-assembly-others']
			}],
			layout:"fit",
			id:"tab7"
		});


		var $tabs = new Ext.TabPanel({
			region:"center",
			id:'mainPanel',
			width:250,
			activeTab:0,
			tbar:[
				{text:"查看种类频率" , iconCls: "bmenu"},
				'-',
				{
					text:"关联股票" , 
					iconCls: "bmenu",
					handler:Vsg.getDefinedEvent("evt_asso_stocks")
					//scope:$tabs
				}
			],
			frame:false,
			margins:{left:8,top:4,right:8,bottom:8},
			items:$tabsArray,
			plain:true
		});
	
		var $layoutBox = [
			$tabs
		];
		
		// --- set layout content -----
		var $layoutContent = {
			layout:"border",
			items:$layoutBox
		};

    	 new Ext.Viewport( $layoutContent );
		
	} catch (e) {
		alert('出现系统性错误，请联系管理人员!');
		//Ext.log("Initial UI error: " + e);
	}
}
// --- run the init method
Vsg.run( init );


/**
 * event
 * @param {Object} $this
 * @param {Object} rowIndex
 * @param {Object} event
 */
Vsg.definedEvent("evt_asso_stocks" , function($this, e) {
	var tabPanel = Ext.getCmp("mainPanel");
	
	// --- get the select record ---
	var actPanel = tabPanel.getActiveTab();
	var childObj = actPanel.find("xtype","iframepanel")[0];
	var iframeWin = childObj.getFrameWindow(); 
	
	var record = iframeWin.getSelectedCategoryRecord();
	
	if (record == undefined) {
		Ext.MessageBox.show({
        	title: "提示",
        	msg: "至少选择一种股票种类!",
        	buttons: Ext.MessageBox.OK,
        	icon: Ext.MessageBox.INFO
       	});			
		return ;
	}
	
    var winHight = document.body.clientHeight - 50;
    var winWidth = document.body.clientWidth - 50;
    var $win = null;
    try {
        $win = new Ext.Window({
            layout: "fit",
            width: winWidth,
            height: winHight,
            loadMask: true,
            modal: true,
            tooltip: {
                text: '显示同一种类的所属关联股票'
            },
            closeAction: "hide",
            title: "关联股票",
            items: [{
                id: "assoPanelId",
                xtype: "iframepanel",
                height: 200,
                border: false,
                loadMask: true,
				header: false,				
                frameConfig: {
                    autoCreate: {
                        name: "extFrameName",
                        frameborder: 0
                    }
                },
                defaultSrc: UrlMKey['stk-category-show']+"?categoryId="+record.id
            }],
            shadow: true,
            border: false
        });
        $win.show(this);
    } 
    catch (e) {
        alert(e);
    }
	
});